package roboticsapp;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton.*;
import javax.swing.plaf.basic.BasicArrowButton;

class MyPanel extends JPanel {

    public MyPanel() {
        setBorder(BorderFactory.createLineBorder(Color.black));
        setBackground(Color.WHITE);
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(700,700);
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);       
        RoboticsApp.robo.draw(g);
    }
}


public class MyFrame extends JFrame 
{
    double currentT1;
    double currentT2;
    double currentT3;
    public MyFrame()
    {
        
        super();
        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton plusButtonone = new JButton("CW");
        plusButtonone.setSize(30, 30);
        
        JButton plusButtontwo= new JButton("CW");
        plusButtontwo.setSize(30, 30);
        JButton plusButtonthree = new JButton("CW");
        plusButtonthree.setSize(30, 30);
        JButton minusButtonone = new JButton("CCW");
        minusButtonone.setSize(30,30);
        JButton minusButtontwo = new JButton("CCW");
        minusButtontwo.setSize(30,30);
        JButton minusButtonthree = new JButton("CCW");
        minusButtonone.setSize(30,30);
        JToggleButton paintButton = new JToggleButton("ON/OFF"); //PAINT TOGGLE
        paintButton.setSize(40,40);
            
        

        JLabel tone= new JLabel("THETA 1:");
        JLabel ttwo= new JLabel("THETA 2:");
        JLabel tthree= new JLabel("THETA 3:");
        JLabel painttoggle = new JLabel("PAINT: ");
       
       
       
        JPanel buttonsPanel = new JPanel();
        buttonsPanel.setLayout(new GridLayout(4,3,10,10)); //second number is columns
        buttonsPanel.setSize(200,200);
        buttonsPanel.add(tone);
        buttonsPanel.add(plusButtonone);
        buttonsPanel.add(minusButtonone);
        buttonsPanel.add(ttwo);
        buttonsPanel.add(plusButtontwo);
        buttonsPanel.add(minusButtontwo);
        buttonsPanel.add(tthree);
        buttonsPanel.add(plusButtonthree);
        buttonsPanel.add(minusButtonthree);
        buttonsPanel.add(painttoggle);
        buttonsPanel.add(paintButton);

     
        
        JPanel controlPanel = new JPanel();
        controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        controlPanel.setSize(300,300);
        controlPanel.add(buttonsPanel);
        
        MyPanel drawingArea = new MyPanel();
        drawingArea.setLayout(new BorderLayout());
        drawingArea.setSize(700,700);
        add(controlPanel, BorderLayout.EAST);
        add(drawingArea, BorderLayout.WEST);
        
        
        
      plusButtonone.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
                System.out.println("Joint 1 CW Button was Clicked");
               RoboticsApp.robo.redraw(getGraphics(),1, -1);
               repaint();
            }
        });
      plusButtontwo.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
                System.out.println("Joint 2 CW Button was Clicked");
               RoboticsApp.robo.redraw(getGraphics(),2, -2);
               repaint();
            }
        });
      plusButtonthree.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
                System.out.println("Joint 3 CW Button was Clicked");
               RoboticsApp.robo.redraw(getGraphics(),3, -5);
               repaint();
            }
        });
      minusButtonone.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
                System.out.println("Joint 1 CCW Button was Clicked"); 
               RoboticsApp.robo.redraw(getGraphics(),1, 1);
               repaint();
            }
        });
      minusButtontwo.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
                System.out.println("Joint 2 CCW Button was Clicked"); 
               RoboticsApp.robo.redraw(getGraphics(),2, 2);
               repaint();
            }
        });
      minusButtonthree.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
                System.out.println("Joint 3 CCW Button was Clicked");
               RoboticsApp.robo.redraw(getGraphics(),3, 5);
               repaint();
            }
        });
      paintButton.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){
               System.out.println("Paint Button was Clicked");             
               RoboticsApp.robo.togglePaint();
               //RoboticsApp.robo.paint(getGraphics());
            }
        });
     
   
    }
    

}
